package cheme.ProcessEditor;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.DelegatingLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Layer;
import org.eclipse.draw2d.LayeredPane;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;

import cheme.ProcessEditor.Figures.IChemeFigure;

/**
 * A transparent figure intended to be added exclusively to a {@link LayeredPane}, who has
 * the responsibilty of managing its layers. 
 */

public class ChemeLayer extends Layer implements IChemeFigure
{
	ChemeLayer()
	{
		super();
		
		setEnabled(true);
		setVisible(true);
		setLayoutManager(new DelegatingLayout());
	}
	
	/**
	 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
	 */
	public Dimension getPreferredSize(int wHint, int hHint) 
	{
		Rectangle rect = new Rectangle();
		
		for (int i = 0; i < getChildren().size(); i++)
		{
			rect.union(((IFigure)getChildren().get(i)).getBounds());
		}
		
		return rect.getSize();
	}
	
	List<IFigure> externalChildren = new ArrayList<IFigure>();
	
	public List<IFigure> getExternalChildren()
	{
		return externalChildren;
	}
	
	public void addExternalChild(IFigure child)
	{
		getExternalChildren().add(child);
	}
	
	public void removeExternalChild(IFigure child)
	{
		getExternalChildren().remove(child);
	}
}
